import 'package:fluent_ui/fluent_ui.dart';

import '../../db/entity/AttributeBean.dart';

///下拉选中框 （带header）
class HeaderDropButton extends StatefulWidget {

  final String header;
  final String text; //显示的内容
  final String attributeCode; //对应的属性code

  final List<AttributeBean> childrenItems; //子项
  final ValueChanged<AttributeBean> changed; //子项选择回调

  const HeaderDropButton(this.attributeCode, this.header, this.text,
      {Key? key, required this.childrenItems, required this.changed})
      : super(key: key);

  @override
  State<StatefulWidget> createState ()=> GyyDrawHeaderState();
}

class GyyDrawHeaderState extends State<HeaderDropButton> {

  late String text;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    text = widget.text;
  }

  @override
  Widget build(BuildContext context) {
    var theme = FluentTheme.of(context);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(widget.header, style: theme.typography.bodyStrong),
        DropDownButton(
          items: widget.childrenItems
              .map(
                (e) => MenuFlyoutItem(
              text: Text(e.attributeName),
              onPressed: () {
                widget.changed(e);
                text = e.attributeName;
                setState(() {

                });
              },
            ),
          )
              .toList(),
          title: Expanded(
            child: Text(text, textAlign: TextAlign.left),
          ),
        ),
      ],
    );
  }

}

